<?php
/**
 * Created by PhpStorm.
 * 处理Echouch Post过来的业务
 * User: caicm
 * Date: 2017/8/24
 * Time: 11:21
 */

namespace WMApi\Controller;


use WMApi\Service\BscService;

class EchouchController extends SellerBaseController {

    public function _initialize() {
        $this->check_sign();
    }

    /**
     * 创建物流点
     * Created By caicm
     */
    public function add_scc(){

        $longitude = I('post.longitude');
        $latitude = I('post.latitude');
        $scc_name = I('post.scc_name');
        $province = I('post.province');
        $city = I('post.city');
        $district = I('post.district');
        $address = I('post.address');
        $radius = I('post.radius');
        $remark = I('post.remark');

        $bsc_service = new BscService();
        $state = $bsc_service->add_scc($longitude, $latitude, $scc_name, $province, $city, $district, $address, $radius, $remark);

        $this->return_data($state);

    }




    /**
     * 验证签名
     * Created By caicm
     * @return bool
     */
    protected function check_sign(){
        $action_time = I('post.action_time');
        $action_sign = I('post.sign');
        $time = time();
        $key = "2MGYTkTs0c9FX88znTNzb6UNBp6Bxv9s";

        if(empty($action_time) || empty($action_sign)){
            returnApiError('参数有误');
        }

        if($action_time < ($time-60)){
            returnApiError('访问超时');
        }

        $sign = md5($key . $action_time);

        if($action_sign != $sign){
            returnApiError('签名有误');
        }

        return true;
    }

    /**
     * 返回接口参数
     * @param $res
     */
    protected function return_data($res){
        echo json_encode($res);
        exit;
    }
}